export const errCodeAndMsg = {
    // 权限限制
    USER_NO_PERMISSION: { code: 2100, msg: "没有权限" },
    // 用户业务错误
    USER_NOT_LOGIN: { code: 2001, msg: "用户未登录" },
    USER_ACCOUNT_EXPIRED: { code: 2002, msg: "账号已过期" },
    USER_ACCOUNT_DISABLE: { code: 2003, msg: "账号不可用" },
    USER_ACCOUNT_NOT_EXIST: { code: 2004, msg: "账号不存在" },
    USER_ACCOUNT_ALREADY_EXIST: { code: 2005, msg: "账号已存在" },
    USER_ACCOUNT_USE_BY_OTHERS: { code: 2006, msg: "账号下线" },
    USER_PWD_ERROR: { code: 2007, msg: "密码错误" },

    // 前端请求，技术错误
    // 400 参数错误
    PARAM_NOT_VALID: { code: 1001, msg: "请求参数无效" },
    PARAM_IS_BLANK: { code: 1002, msg: "请求参数为空" },
    PARAM_TYPE_ERROR: { code: 1003, msg: "请求参数类型错误" },
    PARAM_NOT_COMPLETE: { code: 1004, msg: "请求参数缺失" },

    // 401 token
    TOKEN_IS_BLANK: { code: 4004, msg: "token为空" },
    TOKEN_EXPIRED: { code: 4001, msg: "token过期" },
    TOKEN_INVALID: { code: 4002, msg: "token无效" },
    AUTHENTICATION_FAIL: { code: 4003, msg: "认证失败" },

    // 404
    NotFound: { code: 404, msg: "未找到api, 请检查请求路径以及请求方法是否出错" },

    // 500
    FAIL: { code: 500, msg: "服务器内部错误" },
    FILE_UPLOAD_FAIL: { code: 5001, msg: "文件上传失败" }
};

class Result {
    static ok(ctx, data: any, msg: string = "操作成功") {
        // ctx.set("Content-Type", "application/json;charset=utf8mb4")
        ctx.body = {
            code: 200,
            msg: msg,
            data: data
        };
    }

    static err(ctx, errData: { code: number; msg: string } = errCodeAndMsg.FAIL) {
        // ctx.set("Content-Type", "application/json;charset=utf8mb4")
        ctx.body = errData;
    }
}

export { Result };
